package com.mp.controller.rest;

import com.mp.controller.rest.util.MemoryPriceRest;
import com.mp.controller.rest.util.MensagemRetornoRest;
import com.mp.negocio.HistoricoPrecoService;
import com.mp.negocio.NomeclaturaLocalService;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/Registro")
public class RegistroRest  extends MemoryPriceRest
{
    private HistoricoPrecoService historicoPrecoService = 
            new HistoricoPrecoService();
    private NomeclaturaLocalService nomeclaturaLocalService = 
            new NomeclaturaLocalService();
       
    
    @POST
    @Path("/GravarHistoricoPreco")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public MensagemRetornoRest setHistoricoPreco(
            @FormParam("idSessao") String idSessao,
            @FormParam("idNomeclaturaLocal") String idNomeclatura,
            @FormParam("idItem") String idItem, 
            @FormParam("qtd") String qtd,
            @FormParam("valor") Double valor)
    {
        try
        {   
            historicoPrecoService.gravarHistoricoPreco
                    (
                        Integer.parseInt(idSessao),
                        Integer.parseInt(idNomeclatura),
                        Integer.parseInt(idItem), 
                        Integer.parseInt(qtd), 
                        valor
                    );
            return this.setRetornoCorreto("Ok");
        }
        catch(Exception ex)
        {
            return this.setRetornoComErro(ex);
        }
    }
    
    
    @POST
    @Path("/GravarLocal")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public MensagemRetornoRest setNomeclaturaLocal(
            @FormParam("idSessao") String idSessao, 
            @FormParam("labelEndereco") String labelEndereco,
            @FormParam("descEndereco") String descEndereco,
            @FormParam("idLatitude") String idLatitude,
            @FormParam("idLongitude") String idLongitude)
    {
        try
        {   
            nomeclaturaLocalService.gravarNomeclaturaLocal(labelEndereco,descEndereco,Integer.parseInt(idSessao),idLatitude,idLongitude);
            return this.setRetornoCorreto("Ok");
        }
        catch(Exception ex)
        {
            return this.setRetornoComErro(ex);
        }
    }
    
    
}
